import selectProduct from '@/views/storehouse/components/selectProduct.vue';
import pagination from '@/views/storehouse/components/pagination.vue';
import { listStore } from '@/api/commercial';

export const storeHouseMixin = {
  components: {
    selectProduct,
    pagination,
  },

  data() {
    return {
      transferTypeList: [
        { label: '待审核', value: 0 },
        { label: '通过', value: 1 },
        { label: '驳回', value: 2 },
      ],
      OutWarehouseTypeList: [ //(0:待出库(待入库) 1:已出库(已入库) 2:已取消
        { label: '待出库', value: 0 },
        { label: '已出库', value: 1 },
        { label: '已取消', value: 2 },
      ],
      InWarehouseTypeList: [ //(0:待入库 1:已入库 2:已取消
        { label: '待入库', value: 0 },
        { label: '已入库', value: 1 },
        { label: '已取消', value: 2 },
      ],
      pageType: 1, // 1: 页面列表 2: 详情 3: 新增
      detailData: [],
      storeList: [
        { name: '仓库', id: 1, children: [] },
        { name: '门店', id: 2, children: [] },
      ],
      transferOutStoreId: [],
      transferInStoreId: [],
      transfeInType: '',
      transferOutType: '',
      detailRow: {},
      detailData: [],

    };
  },
  created() {
    this.getStoreList();
  },
  methods: {
 
    resetForm(formName) {
      this.transferOutStoreId = [];
      this.transferInStoreId = [];
      this.transfeInType = '';
      this.transferOutType = '';
      this.$refs[formName].resetFields();
      this.queryParams.inOrOutWarehouseStatus = '';
    },
    getInWarehouseType(type) {
      return this.InWarehouseTypeList.find(item => item.value == type).label;
    },
    getOutWarehouseType(type) {
      return this.OutWarehouseTypeList.find(item => item.value == type).label;
    },  
     getStatusType(status) {
      if (status == '0') return 'warning'
      if (status == '1') return 'success'
      if (status == '2') return 'danger'
      return ''
    },

    getTransferType(type) {
      if (type == 1) {
        return '仓库调拨';
      } else if (type == 2) {
        return '门仓调拨';
      } else if (type == 3) {
        return '门店调拨';
      } else {
        return '';
      }
    },
    getTransferStatus(status) {
      if (status == '0') return '待审核';
      if (status == '1') return '通过';
      if (status == '2') return '驳回';
      return '';
    },
    handleBack() {
      this.pageType = 1;
      this.queryParams.page = 1;
      this.getList();
    },
    getStoreList() {
      // 类型(1仓库 2门仓)
      listStore({ type: 1, page: 1, limit: 999 }).then((res) => {
        this.storeList[0].children = res.list;
      });
      listStore({ type: 2, page: 1, limit: 999 }).then((resr) => {
        this.storeList[1].children = resr.list;
      });
    },
    handleTransferOutStoreChange(val) {
      this.queryParams.transferOutType = val[0];
      try {
        this.transferInType = val[0];
      } catch (error) {
      }


    },
    handleTransferInStoreChange(val) {
      this.queryParams.transferInType = val[0];
      try {
        this.transferInType = val[0];
      } catch (error) {
      }

    },
    //获取随机数
    getRandomNumber() {
      return Math.floor(Math.random() * 1000000) + '-' + Math.floor(Math.random() * 1000000);
    },
  },
};
